package org.example.springbootpra1.demos.services.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.springbootpra1.demos.bean.ChargingPile;
import org.example.springbootpra1.demos.bean.myAccount.RechargeRecord;
import org.example.springbootpra1.demos.data.MyAcountMock;
import org.example.springbootpra1.demos.mapper.MyAccountMapper;
import org.example.springbootpra1.demos.services.service.MyAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MyAccountServiceImpl extends ServiceImpl<MyAccountMapper, RechargeRecord> implements MyAccountService {

    @Autowired
    private MyAccountMapper myAccountMapper;

    @Override
    public IPage<RechargeRecord> getChargingPilePage(){
        Page<RechargeRecord> page = new Page<>(1, 5);

       return myAccountMapper.selectPage(page, new LambdaQueryWrapper<>());

    }


    @Override
    public IPage<RechargeRecord> getChargingPileQueryPage(Page<RechargeRecord> page, QueryWrapper<RechargeRecord> queryWrapper){
        return myAccountMapper.selectPage(page, queryWrapper);

    }


    @Override
    public IPage<RechargeRecord> pageList(int currentPage, int pageSize) {
        // 获取所有账户列表
        List<RechargeRecord> accountList = MyAcountMock.accountList();

        // 创建分页对象
        IPage<RechargeRecord> page = new Page<>(currentPage, pageSize);

        // 计算起始索引和结束索引
        int start = (currentPage - 1) * pageSize;
        int end = Math.min(start + pageSize, accountList.size());

        // 截取当前页的数据
        List<RechargeRecord> currentPageData = accountList.subList(start, end);

        // 设置分页数据
        page.setRecords(currentPageData);

        // 设置总记录数
        page.setTotal(accountList.size());

        return page;
    }

}
